<?php
class Common_model extends CI_Model {

    /*
        通过药店id获取药店名称
        params
            store_id 药店id
    */
    public function getStoreNameByStoreId($store_id = 0)
    {
        $storeInfo = $this->db
            ->where('ID',$store_id)
            ->get('okdkyao.dk_app_yaodian')
            ->row_array();

        return $storeInfo['Caption'];
    }

    /*
        通过药店id获取药店所有信息
        params
            store_id 药店id
    */
    public function getStoreInfoByStoreId($store_id = 0)
    {
        $storeInfo = $this->db
            ->select('ID,Caption,Address,JinDuX,WeiDuY,Tel')
            ->where('ID',$store_id)
            ->get('okdkyao.dk_app_yaodian')
            ->row_array();

        return $storeInfo;
    }

    /*
        获取所有药店名称
        params
    */
    public function getAllStoreName()
    {
        $storeInfo = $this->db
            ->select('ID,Caption')
            ->get('okdkyao.dk_app_yaodian')
            ->result_array();

        return $storeInfo;
    }

    /*
        通过药店ID获取第三方药店信息
        params
    */
    public function getChannelStoreInfoById($chn_id = 0, $store_id = 0)
    {
        $storeInfo = $this->db
            ->select('fk_store_id,other_shop_id,other_shop_name,other_shop_desc,shipping_fee,shipping_start_time,shipping_end_time,store_status')
            ->where('fk_channel_id',$chn_id)
            ->where('fk_store_id',$store_id)
            ->get('kfsy_channel_store.kf_channel_store')
            ->row_array();

        return $storeInfo;
    }

    /*
        获取所有第三方平台信息
        params
    */
    public function getAllChannelInfo($channel_id = 0)
    {
        $channelInfo = array(
            '1' => array('id' => 1, 'name' => '美团'),
            '2' => array('id' => 2, 'name' => '百度'),
            '3' => array('id' => 3, 'name' => '京东'),
            '4' => array('id' => 4, 'name' => '饿了么')
        );

        return empty($channel_id) ? $channelInfo : $channelInfo[$channel_id];
    }

    /*
        获取所有城市列表
        params
            city_id 城市id
    */
    public function getCityList($city_id = '')
    {
        $tabName = "kfsy_admin.kf_sys_city";

        $where = array();


        if(empty($city_id) == false){
            $where['ID'] = $city_id;
        }

        $cityInfo = $this->db
            ->select("ID,Caption,CaptionPY")
            ->where($where)
            ->order_by("ID ASC")
            ->get($tabName)
            ->result_array();

        $res = array();

        foreach ($cityInfo as $key => $value) {
            $res[$value['ID']] = $value;
        }

        return $res;
    }

    /*
        通过城市id获取区域id
        params
            city_id 城市id
    */
    public function getAreaIdByCityId($city_id = 0){
        $tabName = "okdkyao.dk_app_area";

        $where = array();
        $where['MID'] = $city_id;

        $areaInfo = $this->db
            ->select("ID")
            ->where($where)
            ->get($tabName)
            ->result_array();

        $res = array();
        foreach ($areaInfo as $key => $value) {
            $res[] = intval($value['ID']);
        }

        return $res;
    }
}